

package com.maoshi.shop.distribution.comment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maoshi.shop.common.config.Constant;
import com.maoshi.shop.common.util.Json;
import com.maoshi.shop.distribution.comment.dao.DistributionBindSetMapper;
import com.maoshi.shop.distribution.comment.model.DistributionBindSet;
import com.maoshi.shop.distribution.comment.service.DistributionBindSetService;
import com.maoshi.shop.distribution.comment.vo.DistributionBindSceneVO;
import com.maoshi.shop.distribution.comment.vo.DistributionBindSetRobVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 *
 * @author lgh on 2019/04/01.
 */
@Service
public class DistributionBindSetServiceImpl extends ServiceImpl<DistributionBindSetMapper, DistributionBindSet> implements DistributionBindSetService {

    @Autowired
    private DistributionBindSetMapper distributionBindSetMapper;

    @Override
    @Cacheable(cacheNames = "distribution_bind_set", key = "'0'")
    public DistributionBindSet getByShopId() {
        DistributionBindSet distributionBindSet=distributionBindSetMapper.selectOne(new LambdaQueryWrapper<DistributionBindSet>()
            .eq(DistributionBindSet::getShopId, Constant.PLATFORM_SHOP_ID)
        );
//        if(distributionBindSet == null){
//            return createInitialDistributionBindSet(shopId);
//        }
        distributionBindSet.setRob(Json.parseObject(distributionBindSet.getRobJson(), DistributionBindSetRobVO.class));
        distributionBindSet.setBindScene(Json.parseObject(distributionBindSet.getBindSceneJson(), DistributionBindSceneVO.class));
        return distributionBindSet;
    }

//    @Override
//    public DistributionBindSet createInitialDistributionBindSet(Long shopId) {
//        DistributionBindSet distributionBindSet=new DistributionBindSet();
//        distributionBindSet.setShopId(shopId);
//        distributionBindSet.setAttribution(0);
//        distributionBindSet.setRob(new DistributionBindSetRobVO());
//        distributionBindSet.setRobJson(Json.toJsonString(distributionBindSet.getRob()));
//        distributionBindSet.setProtectDay(0);
//        distributionBindSet.setBindScene(new DistributionBindSceneVO());
//        distributionBindSet.setBindSceneJson(Json.toJsonString(distributionBindSet.getBindScene()));
//        distributionBindSetMapper.insert(distributionBindSet);
//        return distributionBindSet;
//    }

    @Override
    @CacheEvict(cacheNames = "distribution_bind_set", key = "'0'")
    public void removeCacheByShopId(Long shopId) {

    }
}
